Test Failed
Push — main ( 402e53...4169bc )
by Ehsan
03:02
created

Bot   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 31
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A retweet 0 20 2
1
import Twit from 'twit';
2
import Debug from 'debug';
3
import Tweet, {TweetConfig} from './entities/Tweet';
4
import Helper from './Helper';
5
import Constant from './Constant';
6
import Like from './actions/Like';
7
import Retweet from './actions/Retweet';
8
import Search from './actions/Search';
9
10
export type BotConfig = {
11
    screenName: string,
12
    debugNamespace?: string,
13
    apiConfig: Twit.Options,
14
    tweetConfig: TweetConfig
15
};
16
17
export default class Bot {
18
    twit: Twit;
19
    config: BotConfig;
20
    debug: Debug.Debugger;
21
22
    constructor(config: BotConfig) {
23
        this.twit = new Twit(config.apiConfig);
24
        this.config = config;
25
        this.debug = Helper.objectExists(config.debugNamespace) && config.debugNamespace ? Debug(config.debugNamespace) : Debug(Constant.DEBUGGER_DEFAULT_NAMESPACE);
26
    }
27
28
    async retweet(searchParams: Twit.Params): Promise<void> {
29
        const like = new Like(this.config, this.twit, this.debug);
30
        const likeOnSuccess = async(tweet: Tweet) => await like.run({
31
            tweet
32
        });
33
34
        const retweet = new Retweet(this.config, this.twit, this.debug);
35
        const retweetOnSuccess = async(tweet: Tweet) => await retweet.run({
36
            tweet,
37
            onSuccess: likeOnSuccess
38
        });
39
40
        const search = new Search(this.config, this.twit, this.debug);
41
        await search.run({
42
            searchParams,
43
            onSuccess: retweetOnSuccess
44
        });
45
46
        this.debug('All done.');
47
    }
48
}